package com.MediaVaultTest;
import com.MediaVaultTest.UserStore;
import java.util.LinkedList;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.blobstore.BlobKey;

@PersistenceCapable
public class Media {

	//!! Keys relating to this class !!//
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	
	//Cover/Thumbnail key
	@Persistent
	private BlobKey Cover; 
	
	@Persistent(mappedBy = "media")
	private LinkedList<Format> Formats;
	
	//!!! MetaData  !!//
	@Persistent
	private String Title;
	
	@Persistent
	private String mediaType;
	
	@Persistent
	private int Rating;
	
	@Persistent
	private String Language;
	
	@Persistent
	private String Album;
	
	@Persistent
	private String Artist;
	
	@Persistent
	private String Genre;
	
	@Persistent
	private String Series;
	
	//!! Parent class !!//
	@Persistent
	private UserStore userStore; 
	
	public Media(Format format, String Title){
		Formats = new LinkedList<Format>();
		Formats.add(format);
		this.Title = Title;
		this.mediaType = "";
		this.Rating = 0;
		this.Language = "";
		this.Album = "";
		this.Artist = "";
		this.Genre = "";
		this.Series = "";
	}

	public String getKeyForTrans(){
		return KeyFactory.keyToString(key);
	}
	
	public int getNumFormats(){
		return Formats.size();
	}
	
	public void addFormat(Format format){
		Formats.add(format);
	}
	
	public LinkedList<Format> getFormatList(){
		return Formats;
	}
	
	public void removeFormat(Format format){
		Formats.remove(format);
	}
	
	public Format getFirstFormat(){
		//Check to make sure there is a format
		if(Formats.size()!=0){
			return Formats.getFirst();
		}
		return null;
	}
	
	public void setKey(Key key) {
		this.key = key;
	}

	public Key getKey() {
		return key;
	}

	public void setCover(BlobKey cover) {
		Cover = cover;
	}

	public BlobKey getCover() {
		return Cover;
	}

	public String getCoverForTrans(){
		if(Cover==null){
			return "";
		} else {
			return Cover.getKeyString();
		}
	}
	
	public void setTitle(String title) {
		Title = title;
	}

	public String getTitle() {
		return Title;
	}

	public void setMediaType(String mediaType) {
		this.mediaType = mediaType;
	}

	public String getMediaType() {
		if(mediaType==null){
			mediaType = "";
		}
		return mediaType;
	}

	public void setRating(int rating) {
		Rating = rating;
	}

	public int getRating() {
		return Rating;
	}

	public void setLanguage(String language) {
		Language = language;
	}

	public String getLanguage() {
		if(Language==null){
			Language = "";
		}
		return Language;
	}

	public void setAlbum(String album) {
		Album = album;
	}

	public String getAlbum() {
		if(Album==null){
			Album = "";
		}
		return Album;
	}

	public void setArtist(String artist) {
		Artist = artist;
	}

	public String getArtist() {
		if(Artist==null){
			Artist = "";
		}
		return Artist;
	}

	public void setGenre(String genre) {
		Genre = genre;
	}

	public String getGenre() {
		if(Genre==null){
			Genre = "";
		}
		return Genre;
	}

	public void setSeries(String series) {
		Series = series;
	}

	public String getSeries() {
		if(Series==null){
			Series = "";
		}
		return Series;
	}
	
	public UserStore getUserStore() {
		return userStore;
	}
}
